import React from 'react'
import { Space } from 'antd'
import style from './Btn.module.less'

// 默认送达按钮
function Main ({ data = {}, theme = {}, editable, utils }) {
  const { status, to_type: toType, send_datetime: sendDatetime } = data
  if (toType === '电子送达') {
    if (sendDatetime) {
      return (
        <Space>
          <span className={style.btn} onClick={() => utils.detailfn('electronicDetailVisible')}>查看详情</span>
          <span className={style.btn} onClick={() => utils.detailfn('electronicResultVisible')}>查看结果</span>
        </Space>
      )
    }
    return (
      <Space>
        {editable ? <span className={style.btn} onClick={() => utils.detailfn('normalModalVisible')}>编辑</span> : null}
        <span className={style.btn} onClick={() => utils.confirmSend()}>发送</span>
        <span className={style.btn} onClick={() => utils.delFn()}>作废</span>
      </Space>
    )
  }
  if (theme.complete_datetime && toType === 'EMS') {
    return (
      <Space>
        <span className={style.btn} onClick={() => utils.detailfn('normalDetailModalVisible')}>查看详情</span>
        <span className={style.btn} onClick={() => utils.detailfn('emsModalVisible')}>查看邮单</span>
      </Space>
    )
  }
  if (status === '作废' || (theme.complete_datetime && toType !== 'EMS')) {
    return <span className={style.btn} onClick={() => utils.detailfn('normalDetailModalVisible')}>查看详情</span>
  }
  if (['打印邮单', '录入邮单'].indexOf(status) !== -1) {
    return (
      <Space>
        <span className={style.btn} onClick={() => utils.detailfn('normalDetailModalVisible')}>查看详情</span>
        <span className={style.btn} onClick={() => utils.printFn(true)}>打印</span>
        <span className={style.btn} onClick={() => utils.detailfn('emsModalVisible')}>
          {status === '打印邮单' ? '录入邮单' : '查看邮单'}
        </span>
        <span className={style.btn} onClick={() => utils.delFn()}>作废</span>
      </Space>
    )
  }
  if (['送达', '视为送达', '送达失败'].indexOf(status) !== -1) {
    return (
      <Space>
        <span className={style.btn} onClick={() => utils.detailfn('normalDetailModalVisible')}>查看详情</span>
        <span className={style.btn} onClick={() => utils.detailfn('emsModalVisible')}>查看邮单</span>
        <span className={style.btn} onClick={() => utils.delFn()}>作废</span>
      </Space>
    )
  }
  return (
    <Space>
      {editable ? <span className={style.btn} onClick={() => utils.detailfn('arbitratorModalVisible')}>编辑</span> : null}
      <span className={style.btn} onClick={() => utils.printFn(true)}>打印</span>
      <span className={style.btn} onClick={() => utils.delFn()}>作废</span>
    </Space>
  )
}

export default Main
